package com.ylbh.modules.hotwords.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.hotwords.dto.HotWordsDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.hotwords.entity.ShoppingHotWords;
import com.ylbh.modules.hotwords.service.ShoppingHotWordsService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author: czx
 * @date: 2019/08/03 17:34
 */
@RestController
@RequestMapping("search")
public class ShoppingHotWordsController {

    @Autowired
    private ShoppingHotWordsService shoppingHotWordService;

    @ApiOperation("获取搜索热词列表")
    @GetMapping("queryHotWordsList")
    @RequiresPermissions("search:queryHotWordsList")
    public CommonResult<PageUtils> queryHotWordsList(HotWordsDTO hotWordsDTO) {
        PageUtils page = shoppingHotWordService.queryHotWordsList(hotWordsDTO);
        return Ref.ok(page);
    }

    @ApiOperation("获取搜索热词详情")
    @GetMapping("getHotWordsDetails/{id}")
    @RequiresPermissions("search:getHotWordsDetails")
    public CommonResult<ShoppingHotWords> getHotWordsDetails(@PathVariable String id) {
        ShoppingHotWords vo = shoppingHotWordService.getHotWordsList(id);
        return Ref.ok(vo);
    }

    @SysLog("修改热词搜索详情")
    @ApiOperation("修改热词搜索详情")
    @PostMapping("modifyHotWords")
    @RequiresPermissions("search:modifyHotWords")
    public CommonResult modifyHotWords(@RequestBody ShoppingHotWords shoppingHotWords) {
        shoppingHotWordService.modifyHotWords(shoppingHotWords);
        return Ref.ok();
    }

    @SysLog("新增热词搜索")
    @ApiOperation("新增热词搜索")
    @PostMapping("addHotWords")
    @RequiresPermissions("search:addHotWords")
    public CommonResult addHotWords(@RequestBody ShoppingHotWords shoppingHotWords) {
        shoppingHotWordService.addHotWords(shoppingHotWords);
        return Ref.ok();
    }

    @SysLog("热词上下架操作")
    @ApiOperation("热词上下架操作")
    @PostMapping("modifyUpperAndLowerRacksById/{id}/{hotSale}")
    @RequiresPermissions("search:modifyUpperAndLowerRacksById")
    public CommonResult modifyUpperAndLowerRacksById(@PathVariable String id, @PathVariable Integer hotSale) {
        shoppingHotWordService.modifyUpperAndLowerRacksById(id, hotSale);
        return Ref.ok();
    }

    @SysLog("删除热词")
    @ApiOperation("删除热词")
    @PostMapping("removeHotWordsById")
    @RequiresPermissions("search:removeHotWordsById")
    public CommonResult removeHotWordsById(@RequestBody String[] ids) {
        shoppingHotWordService.removeHotWordsById(Arrays.asList(ids));
        return Ref.ok();
    }

    @ApiOperation("热词类型数量")
    @PostMapping("queryTypeNum")
    public CommonResult<List> queryTypeNum() {
        List num = shoppingHotWordService.queryTypeNum();
        return Ref.ok(num);
    }
}
